home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / flight-of-the-museum.swf / scripts / com / google / analytics / debug / Label.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  3.5 KB  |  136 lines

  1. package com.google.analytics.debug
  2. {
  3.    import flash.display.Graphics;
  4.    import flash.display.Shape;
  5.    import flash.events.TextEvent;
  6.    import flash.text.TextField;
  7.    import flash.text.TextFieldAutoSize;
  8.    import flash.text.TextFieldType;
  9.    
  10.    public class Label extends UISprite
  11.    {
  12.       
  13.       public static var count:uint = 0;
  14.        
  15.       
  16.       private var _color:uint;
  17.       
  18.       private var _background:Shape;
  19.       
  20.       private var _textField:TextField;
  21.       
  22.       public var stickToEdge:Boolean;
  23.       
  24.       private var _text:String;
  25.       
  26.       protected var selectable:Boolean;
  27.       
  28.       private var _tag:String;
  29.       
  30.       public function Label(text:String = "", tag:String = "uiLabel", color:uint = 0, alignement:Align = null, stickToEdge:Boolean = false)
  31.       {
  32.          super();
  33.          this.name = "Label" + count++;
  34.          selectable = false;
  35.          _background = new Shape();
  36.          _textField = new TextField();
  37.          _text = text;
  38.          _tag = tag;
  39.          if(alignement == null)
  40.          {
  41.             alignement = Align.none;
  42.          }
  43.          this.alignement = alignement;
  44.          this.stickToEdge = stickToEdge;
  45.          if(color == 0)
  46.          {
  47.             color = uint(Style.backgroundColor);
  48.          }
  49.          _color = color;
  50.          _textField.addEventListener(TextEvent.LINK,onLink);
  51.       }
  52.       
  53.       public function get tag() : String
  54.       {
  55.          return _tag;
  56.       }
  57.       
  58.       private function _draw() : void
  59.       {
  60.          var g:Graphics = _background.graphics;
  61.          g.clear();
  62.          g.beginFill(_color);
  63.          var W:uint = _textField.width;
  64.          var H:uint = _textField.height;
  65.          if(forcedWidth > 0)
  66.          {
  67.             W = forcedWidth;
  68.          }
  69.          Background.drawRounded(this,g,W,H);
  70.          g.endFill();
  71.       }
  72.       
  73.       public function get text() : String
  74.       {
  75.          return _textField.text;
  76.       }
  77.       
  78.       public function appendText(value:String, newtag:String = "") : void
  79.       {
  80.          if(value == "")
  81.          {
  82.             return;
  83.          }
  84.          if(newtag == "")
  85.          {
  86.             newtag = tag;
  87.          }
  88.          _textField.htmlText += "<span class=\"" + newtag + "\">" + value + "</span>";
  89.          _text += value;
  90.          _draw();
  91.          resize();
  92.       }
  93.       
  94.       public function set text(value:String) : void
  95.       {
  96.          if(value == "")
  97.          {
  98.             value = _text;
  99.          }
  100.          _textField.htmlText = "<span class=\"" + tag + "\">" + value + "</span>";
  101.          _text = value;
  102.          _draw();
  103.          resize();
  104.       }
  105.       
  106.       override protected function layout() : void
  107.       {
  108.          _textField.type = TextFieldType.DYNAMIC;
  109.          _textField.autoSize = TextFieldAutoSize.LEFT;
  110.          _textField.background = false;
  111.          _textField.selectable = com.google.analytics.┬ºdebug:Label┬º.selectable;
  112.          _textField.multiline = true;
  113.          _textField.styleSheet = Style.sheet;
  114.          this.text = _text;
  115.          addChild(_background);
  116.          addChild(_textField);
  117.       }
  118.       
  119.       public function set tag(value:String) : void
  120.       {
  121.          _tag = value;
  122.          text = "";
  123.       }
  124.       
  125.       public function onLink(event:TextEvent) : void
  126.       {
  127.       }
  128.       
  129.       override protected function dispose() : void
  130.       {
  131.          _textField.removeEventListener(TextEvent.LINK,onLink);
  132.          super.dispose();
  133.       }
  134.    }
  135. }
  136.